package com.situ.springboot.controller;

import com.situ.springboot.pojo.Blog;
import com.situ.springboot.pojo.query.BlogQuery;
import com.situ.springboot.service.IBlogService;
import com.situ.springboot.util.LayUITableResult;
import com.situ.springboot.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/blog")
public class BlogController {
    @Autowired
    private IBlogService blogService;

    @RequestMapping("/toAdd")
    public String toAdd() {
        return "blog_add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public Result add(Blog blog) {
        blogService.add(blog);
        return Result.ok("添加成功");
    }

    @RequestMapping("/deleteAll")
    @ResponseBody
    public Result deleteAll(Integer[] ids) {
        blogService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public Result deleteById(Integer id) {
        blogService.deleteById(id);
        return Result.ok("删除成功");
    }

    @RequestMapping("/toList")
    public String toList() {
        return "blog_list";
    }

    //http://localhost:8080/blog/list?page=1&limit=10
    //http://localhost:8080/blog/list?page=1&limit=10&name=zhangsan&email=shsdh
    @RequestMapping("/list")
    @ResponseBody
    public LayUITableResult list(BlogQuery blogQuery) {
        LayUITableResult layUITableResult = blogService.list(blogQuery);
        return layUITableResult;
    }

}
